package com.thon.controller.system;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.thon.entity.system.Event;
import com.thon.service.system.EventService;

/**
 * @author 张先吉
 * @email
 * @date 2013年11月15日
 * @descripts
 */

@Controller
public class EventController {
	@Autowired
	private EventService eventService;

	@SuppressWarnings("finally")
	@RequestMapping(value = "event")
	public String addEvent(Event event, Model model) {
		try {
			if (!event.getName().equals("")) {
				eventService.addEvent(event);
			}
		} catch (Exception e) {}
		finally{
		List<Event> events = eventService.listAllEvent();
		model.addAttribute("events", events);
		return "event";
		}
	}
	
	@RequestMapping(value="event/{id}")
	public String deleteEvent(@PathVariable(value="id") int id){
		eventService.deleteEvent(id);
		return "redirect:/event";
	}
}
